package com.cdtye.itps.cms.config;

import com.cdtye.common.kafkacore.service.KafkaConsumerSubscribeService;
import com.cdtye.itps.cms.service.datasysn.DetectConsumerService;
import com.cdtye.itps.cms.service.datasysn.WsHandlerImpl;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@ConditionalOnProperty(value = "kafka.enabled", havingValue = "true")
public class KafkaConfig implements InitializingBean {

    @Autowired
    private KafkaConsumerSubscribeService kafkaConsumerSubscribeService;
    @Autowired
    private DetectConsumerService detectConsumerService;
    @Autowired
    private WsHandlerImpl wsHandlerImpl;

    @Value("${topic.itps.detailplan}")
    private String topicDetailPlan;
    @Value("${topic.itps.c124detect}")
    private String c124detect;
    @Value("${topic.itps.defect}")
    private String topicDefect;

    public String topicWsmsg = "topic_itps_wsmsg";

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("================================================================");
        //订阅消费websocket消息
        String consumerGroupId = "consumer_itps_wsmsg_" + Math.random();
        kafkaConsumerSubscribeService.consumer(topicWsmsg, consumerGroupId, wsHandlerImpl, "saveHandleWsMsg");


        Thread.sleep(6000);
        //订阅消费1C、2C、4C文件包数据
        kafkaConsumerSubscribeService.consumer(c124detect, detectConsumerService, "saveHandleConsumerDefectPlan");

        Thread.sleep(6000);
        //订阅消费缺陷数据
        kafkaConsumerSubscribeService.consumer(topicDefect, detectConsumerService, "saveHandleConsumerShuoHuangDefectInfos");

        Thread.sleep(6000);
        //订阅消费检测计划数据
        kafkaConsumerSubscribeService.consumer(topicDetailPlan, detectConsumerService, "saveHandleConsumerShuoHuangPlanInfos");

    }
}
